<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>

<style>
	label{display:inline-block;width:90px;text-align:right;line-height:18px;}
	.swfupload{position:relative;top:5px;}
	* html select{line-height:auto;width:95px;}
	.loading{display:none;}
</style>

<link rel='stylesheet' href='resources/css/jquerylib/validationEngine.jquery.css'/>
<link rel="stylesheet" type="text/css" href="resources/css/jquerylib/jquery.autocomplete.css" />
<script type='text/javascript' src='resources/js/jquerylib/jquery.autocomplete.js'></script>
<script type="text/javascript" src="resources/js/jquerylib/jquery.validationEngine.js"></script>
<script type="text/javascript" src="resources/js/jquerylib/jquery.validationEngine-cn.js"></script>
<script type="text/javascript" src="resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="resources/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="resources/js/swfupload/handlers.js"></script>
<script type="text/javascript" src="dwr/interface/ServiceSystem.js"></script> 
<script type="text/javascript" src="dwr/interface/ServiceDistrict.js"></script> 

<script>
	
	function onePhoneNeeded(){
		if ($.trim($("#student_father_phone").val()) == "" && $.trim($("#student_mother_phone").val()) == ""){
			return true;
		}else{
			return false;
		}
	}
	
	function textAutoComplete(wrapper, data) {
		$("#"+wrapper).autocomplete(data, {
			width: 159,
			dataType: 'json',
			matchContains: true,
			target: $(this),
			parse: function(data){
				var rows = [];
				if(data.length > 0){
					for(var i = 0; i < data.length; i++){
						if(data[i] != null){
							rows[rows.length] = {    
								data:data[i].optionValue,
								value:data[i].optionValue,
								result:data[i].optionValue
							};   
						}
					}
				}
				return rows; 
			},
			formatItem: function(row, i, max) {
				return row.optionValue;
			},
			beforeSendRequest: function(){
			}
		});
	}

	$(function(){
		
		// polish the droplist for birthday datepicker
		polish_year_droplist("date_year","<c:if test='${data[\"birthYear\"] != null}'><c:out value='${data[\"birthYear\"]}' /></c:if>");
		polish_month_droplist("date_month","<c:if test='${data[\"birthMonth\"] != null}'><c:out value='${data[\"birthMonth\"]}' /></c:if>");
		polish_day_droplist("date_day","<c:if test='${data[\"birthDay\"] != null}'><c:out value='${data	[\"birthDay\"]}' /></c:if>");
		
		// polish the alternative input focus hover
		$.each($("input.text"),function(){
			$(this).focus(function(){$(this).addClass("textfocus")}).blur(function(){$(this).removeClass("textfocus")});
		});
		
		$("#student_primary_school").keyup(function(){
			var val = $(this).val();
			ServiceSystem.getModelSystemOptionListBySlugAndValue("school_primary", val, {
				callback: function(data){
					textAutoComplete("student_primary_school", data);
				}
			});
		});
		
		$("#student_middle_school").keyup(function(){
			var val = $(this).val();
			ServiceSystem.getModelSystemOptionListBySlugAndValue("school_middle", val, {
				callback: function(data){
					textAutoComplete("student_middle_school", data);
				}
			});	
		});
		
		$("#student_senior_school").keyup(function(){
			var val = $(this).val();
			ServiceSystem.getModelSystemOptionListBySlugAndValue("school_senior", val, {
				callback: function(data){
					textAutoComplete("student_senior_school", data);
				}
			});
		});
		
		$("#area_province").change(function(){
			var val = $(this).val();
			ServiceDistrict.getSubDistrictsByParent(val, {
				callback: function(data){
					DWRUtil.removeAllOptions("area_district");
					DWRUtil.addOptions("area_district",data,"id","districtName");
				}
			});
		});
		
		$("#std_form").validationEngine();
		
	});
</script>

<form method="post" action="admin/maintenance/student_save" id="std_form" name="std_form">
	
	<!-- PhotoFace -->
	<div class="avatar48 alignleft" style="margin:10px 0 0 10px;">
		<img class="imgpreview" src="<logic:notPresent name='entity' property='studentPhoto'>resources/images/layout/avatar_blank.gif</logic:notPresent><logic:present name='entity' property='studentPhoto'>uploads/small/<bean:write name='entity' property='studentPhoto' /></logic:present>" height="48px" width="48px" />
	</div>
	
	<table cellspacing="10" cellpadding="3">
		<col width="300px" />
		<col width="300px" />
		<!--
		<tr>
			<td>
				<label>照片：</label>
				<input type="hidden" name="studentPhoto" id="student_photo" /><c:if test="${__opercode == null || __opercode['oper.fileupload'] != null}" ><span id="spanButtonPlaceHolder"></span><input id="btnCancel" class="button" style="display:none" type="button" value="取消上传" onclick="swfu.cancelQueue();" disabled="disabled" style="" /><img src='resources/images/layout/loading.gif' class='loading' /></c:if>
			</td>
		</tr>
		-->
		<tr>
			<td>
				<label>中文姓名：</label>
				<input type="text" class="text validate[required]" id="student_cname" name="studentCName" value="<logic:present name='entity'><bean:write name='entity' property='studentCName' /></logic:present>"/>
			</td>
			<td>
				<label>英文姓名：</label>
				<input type="text" class="text" id="student_ename" name="studentEName"  value="<logic:present name='entity'><bean:write name='entity' property='studentEName' /></logic:present>"/>
			</td>
		</tr>
		<tr>
			<td>
				<label>性　　别：</label>
				<select id="student_sex" name="studentSex" value="<logic:present name='entity'><bean:write name='entity' property='studentSex' /></logic:present>">
					<option value="1">男</option>
					<option value="2">女</option>
				</select>
			</td>
			<td colspan="2">
				<label>出生时间：</label>
				<select name="birthYear" id="date_year"></select>
				<select id="date_month" name="birthMonth"></select>
				<select id="date_day" name="birthDay"></select>
			</td>
		</tr>
		<tr>
			<td>
				<label>年　　级：</label>
				<input type="text" class="text validate[required]" id="student_age" name="studentAge" value="<logic:present name='entity'><bean:write name='entity' property='studentAge' /></logic:present>"/>
			</td>
			<td>
				<label>就读公立小学：</label>
				<input type="text" class="text" id="student_primary_school" name="studentPrimarySchool" value="<logic:notEmpty name='entity'><bean:write name='entity' property='studentPrimarySchool' /></logic:notEmpty>"/><img id="_loading_data_school_primary" src="resources/images/layout/loading.gif" style='display:none' align='absmiddle' />
			</td>
		</tr>
		<tr>
			<td>
				<label>就读公立中学：</label>
				<input type="text" class="text" id="student_middle_school" name="studentMiddleSchool" value="<logic:notEmpty name='entity'><bean:write name='entity' property='studentMiddleSchool' /></logic:notEmpty>"/><img id="_loading_data_school_middle" src="resources/images/layout/loading.gif" style='display:none' align='absmiddle' />
			</td>
			<td>
				<label>就读公立高中：</label>
				<input type="text" class="text" id="student_senior_school" name="studentSeniorSchool" value="<logic:notEmpty name='entity'><bean:write name='entity' property='studentSeniorSchool' /></logic:notEmpty>"/><img id="_loading_data_school_senior" src="resources/images/layout/loading.gif" style='display:none' align='absmiddle' />
			</td>
		</tr>
		<tr>
			<td>
				<label>家庭所在地区：</label>
				<select id="area_province">
					<option selected="selected">请选择省</option>
					<logic:present name="districts">
						<logic:iterate name="districts" id="district">
							<option value="${district.id}">${district.districtName}</option>
						</logic:iterate>
					</logic:present>
				</select>
				<select id="area_district">
					<option selected="selected">请选择区域</option>
				</select>
				<%--
				<input type="text" class="text validate[required]" id="student_home_region" name="studentHomeRegion" value="<logic:present name='entity'><bean:write name='entity' property='studentHomeRegion' /></logic:present>"/>
				--%>
			</td>
			<td>
				<label>固定电话：</label>
				<input type="text" class="text validate[required]" id="student_home_phone" name="studentHomePhone" value="<logic:present name='entity'><bean:write name='entity' property='studentHomePhone' /></logic:present>"/>
			</td>
		</tr>
		<tr>
			<td>
				<label>邮　　箱：</label>
				<input type="text" id="student_email" class="text validate[optional,email]" size="" name="studentEmail" value="<logic:present name='entity'><bean:write name='entity' property='studentEmail' /></logic:present>"/>
			</td>
			<td>
				<label>家庭地址：</label>
				<input type="text" id="student_home_address" class="text" size="" name="studentHomeAddress"  value="<logic:present name='entity'><bean:write name='entity' property='studentHomeAddress' /></logic:present>"/>
			</td>
		</tr>
		<tr>
			<td>
				<label>父亲姓名：</label>
				<input type="text" class="text" id="student_father" name="studentFather" value="<logic:present name='entity'><bean:write name='entity' property='studentFather' /></logic:present>"/>
			</td>
			<td>
				<label>手机号码：</label>
				<input type="text" class="text validate[funcCall[onePhoneNeeded],onlyTelephone]" id="student_father_phone" name="studentFatherPhone" value="<logic:present name='entity'><bean:write name='entity' property='studentFatherPhone' /></logic:present>"/>
			</td>
			<td>
				<label style="text-align:left;width:auto;">工作单位：</label>
				<select id="stu_fcom" name="studentFatherCompany">
					<option <logic:notEmpty name='entity' property='studentFatherCompany'><logic:equal name='entity' property='studentFatherCompany' value="1">selected="selected"</logic:equal></logic:notEmpty> value="1">暂无单位</option>
					<option <logic:notEmpty name='entity' property='studentFatherCompany'><logic:equal name='entity' property='studentFatherCompany' value="2">selected="selected"</logic:equal></logic:notEmpty> value="2">事业单位</option>
					<option <logic:notEmpty name='entity' property='studentFatherCompany'><logic:equal name='entity' property='studentFatherCompany' value="3">selected="selected"</logic:equal></logic:notEmpty> value="3">企业单位</option></select>
			</td>
		</tr>
		<tr>
			<td>
				<label>母亲姓名：</label>
				<input type="text" class="text" id="student_mother" name="studentMother" value="<logic:present name='entity'><bean:write name='entity' property='studentMother' /></logic:present>"/>
			</td>
			<td>
				<label>手机号码：</label>
				<input type="text" class="text validate[onlyTelephone]" id="student_mother_phone" name="studentMotherPhone" value="<logic:present name='entity'><bean:write name='entity' property='studentMotherPhone' /></logic:present>"/>
			</td>
			<td>
				<label style="text-align:left;width:auto;">工作单位：</label>
				<select id="stu_mcom" name="studentMotherCompany">
					<option <logic:notEmpty name='entity' property='studentMotherCompany'><logic:equal name='entity' property='studentMotherCompany' value="1">selected="selected"</logic:equal></logic:notEmpty> value="1">暂无单位</option>
					<option <logic:notEmpty name='entity' property='studentMotherCompany'><logic:equal name='entity' property='studentMotherCompany' value="2">selected="selected"</logic:equal></logic:notEmpty> value="2">事业单位</option>
					<option <logic:notEmpty name='entity' property='studentMotherCompany'><logic:equal name='entity' property='studentMotherCompany' value="3">selected="selected"</logic:equal></logic:notEmpty> value="3">企业单位</option>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<label>培训期望：</label>
				<input type="text" class="text" id="student_expectation" size="127" name="studentExpectation" value="<logic:present name='entity'><bean:write name='entity' property='studentExpectation' /></logic:present>"/>
			</td>
		</tr>
		<tr>
			<td colspan="3" align="right">
				<input type="button" value="返回" id="btnback" class="small-btn" style="padding:0 0 7px 2px;text-align:center;" onclick="javascript:window.location.href='${from != null ? from : 'admin/maintenance/student'}'"/><input type="submit" value="保存" id="nextstep"  class="small-btn" style="padding:0 0 7px 2px;text-align:center;"/>
			</td>
		</tr>
	</table>
	<input type="hidden" name="id" value="<bean:write name='entity' property='id' />" />
</form>
